package cn.tpshion.config.support;

import org.apache.curator.framework.CuratorFramework;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextClosedEvent;
import org.springframework.stereotype.Component;

import java.util.Objects;

@Component
public class CloseListener implements ApplicationListener<ContextClosedEvent> {

    @Override
    public void onApplicationEvent(ContextClosedEvent event) {
        // 断开配置中心连接
        CuratorFramework zkClient = MySpringApplicationRunListener.getZkClient();
        if(Objects.nonNull(zkClient)){
            zkClient.close();
        }
    }
}
